package com.woniuxy.oa.entity;

import java.util.List;

public class PageBeanList<T> {
	//成员变量 字段
	//数据库查询 自己要显示的对象
	private List<T> beanList;
	//当前页 当前页 页索引 客户请求参数
	//就是客户想看第几页的
	private int pageIndex;
	//每页显示的条数 页大小 每页显示的数据条数 业务规定
	private int pageSize;
	//总记录条数 count(*)
	//数据库查询  这个条件下一共有多少条记录
	private int totalRecored;
	//总页数 就是页面一共显示多少页码
	private int totalPage;
	//开始显示页数 用户第一次访问时显示多少页码
	private int pageBean;
	//最后显示页数 用户第一次访问时结束页码显示时多少
	private int pageEnd;
	//封装请求路径参数 存储请求路径
	private String url;
	
	//写一个自动赋值的方法 来确定起始页和结束页
	public void setPageBeginAndPageEnd() {
		//不够十页
		if(getTotalPage()<10) {
			pageBean=1;
			pageEnd=getTotalPage();
		}else {
			pageBean=pageIndex-5;
			pageEnd=pageIndex+4;
			//上边界越界
			if(pageIndex-5<1) {
				pageBean=1;
				pageEnd=10;
			}
			//下边界越界
			if(pageIndex+4>getTotalPage()) {
				pageBean=getTotalPage()-9;
				pageEnd=getTotalPage();
			}
		}
	}
	
	public PageBeanList() {
		super();
		// TODO Auto-generated constructor stub
	}
	public PageBeanList(List<T> beanList, int pageIndex, int pageSize, int totalRecored, int totalPage, int pageBean,
			int pageEnd, String url) {
		super();
		this.beanList = beanList;
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.totalRecored = totalRecored;
		this.totalPage = totalPage;
		this.pageBean = pageBean;
		this.pageEnd = pageEnd;
		this.url = url;
	}
	public List<T> getBeanList() {
		return beanList;
	}
	public void setBeanList(List<T> beanList) {
		this.beanList = beanList;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalRecored() {
		return totalRecored;
	}
	public void setTotalRecored(int totalRecored) {
		this.totalRecored = totalRecored;
	}
	public int getTotalPage() {
		return totalRecored%pageSize==0?totalRecored/pageSize:totalRecored/pageSize+1;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getPageBean() {
		return pageBean;
	}
	public void setPageBean(int pageBean) {
		this.pageBean = pageBean;
	}
	public int getPageEnd() {
		return pageEnd;
	}
	public void setPageEnd(int pageEnd) {
		this.pageEnd = pageEnd;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	@Override
	public String toString() {
		return "PageBean [beanList=" + beanList + ", pageIndex=" + pageIndex + ", pageSize=" + pageSize
				+ ", totalRecored=" + totalRecored + ", totalPage=" + totalPage + ", pageBean=" + pageBean
				+ ", pageEnd=" + pageEnd + ", url=" + url + "]";
	}
	
}
